//
//  TrainFinderConst.h
//  TrainFinder3
//
//  Created by 饶首建 on 17/2/28.
//  Copyright © 2017年 com.ikamobile.trainfinder3. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef enum : NSUInteger {
    ControlTypeGang,
    ControlTypeHu,
    ControlTypeCha,
} ControlType;

typedef enum : NSUInteger {
    SitPositionTypeEast,
    SitPositionTypeWest,
    SitPositionTypeSouth,
    SitPositionTypeNorth,
} SitPositionType;

#if DEBUG
    #define Log(fmt,...) do {                      \
    NSString *file = [[NSString alloc] initWithFormat:@"%s", __FILE__];             \
    NSLog((@"FILE:%@; Line:%d; FUNC:%s \n>:"  fmt), [file lastPathComponent], __LINE__, __func__, ##__VA_ARGS__);        \
    } while(0)
#else
    #define Log(...)
#endif

#define IOS8 ([[UIDevice currentDevice].systemVersion compare:@"8.0"] != NSOrderedAscending)
#define IOS9 ([[UIDevice currentDevice].systemVersion compare:@"9.0"] != NSOrderedAscending)
#define IOS_VERSION_GREATER(version) ([[UIDevice currentDevice].systemVersion compare:version] != NSOrderedAscending)

#define NSStringFormat(fmt,...) [NSString stringWithFormat:fmt, ##__VA_ARGS__]

#define THEMCOLOR                           UIColorHex(#5B65B8)
#define THEM_TEXT_COLOR                     UIColorHex(#4B506D)
#define THEM_TEXT_LIGHT_COLOR               UIColorHex(#9DA0AB)
#define THEM_TEXT_HIGHTLIGHT_COLOR          UIColorHex(#EAEAEA)



#define DEFAULT_BACKGROUND_COLOR            UIColorHex(#FAFAFA)

#define THEM_ORANGE_COLOR                   UIColorHex(#EE8222)//FF7F00
#define THEM_GREEN_COLOR                    UIColorHex(#8BB335)
#define THEM_RED_COLOR                      UIColorHex(#F0632D)

#define kClearColor [UIColor clearColor]

#define NavigationBarHeight 64.f

UIKIT_EXTERN NSString * const BASE_URL;
UIKIT_EXTERN NSString * const BASE_SOCKETIO_URL;
UIKIT_EXTERN NSString * const WECHAT_QRCODE_URL;

UIKIT_EXTERN NSString * const API_NEW_MATCH;
UIKIT_EXTERN NSString * const API_GET_PATTERN;
UIKIT_EXTERN NSString * const API_GET_RULE;
UIKIT_EXTERN NSString * const API_GET_MATCH;
UIKIT_EXTERN NSString * const API_POST_JOIN_MATCH;
UIKIT_EXTERN NSString * const API_POST_USERJOIN_MATCH;

UIKIT_EXTERN NSString * const NOTIFICATION_CONNECTED_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_ERROR_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_DISCONNECTED_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_NEWGAME_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_ACTION_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_MATCH_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_ME_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_MATCH_LEAVE_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_MATCH_BACK_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_MATCH_WAIT_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_MATCH_RECONNECT_CALLBACK;
UIKIT_EXTERN NSString * const NOTIFICATION_MATCH_CHANGE_SEAT_CALLBACK;
UIKIT_EXTERN NSString * const TABLE_ID;

UIKIT_EXTERN NSString * const NSUSERDEFAULTS_KEY_SITPOSITION;

#pragma mark - Color系列
inline static UIColor* RGBA(CGFloat r, CGFloat g, CGFloat b, CGFloat a) {
    return [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a];
}

#pragma mark - 屏幕宽度系列
inline static CGFloat SWidth() {
    return CGRectGetWidth([UIScreen mainScreen].bounds);
}

inline static CGFloat SHeight() {
    return CGRectGetHeight([UIScreen mainScreen].bounds);
}

inline static UIImage* UIImageWithName(NSString *imageName) {
    return [UIImage imageNamed:imageName];
}

inline static UIFont* DefaultSystemFont(CGFloat fontSize) {
    return [UIFont systemFontOfSize:fontSize];
}

inline static UIFont* SystemBoldFont(CGFloat fontSize) {
    return [UIFont boldSystemFontOfSize:fontSize];
}

inline static UIFont* SystemFont(CGFloat fontSize, CGFloat weight) {
    if (IOS_VERSION_GREATER(@"8.2")) {
        return [UIFont systemFontOfSize:fontSize weight:weight];
    }
    return [UIFont boldSystemFontOfSize:fontSize];
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
static id DateFormater(id obj, NSString *formatter) {
    static NSDateFormatter *dateFormat;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dateFormat = [[NSDateFormatter alloc] init];
    });
    dateFormat.dateFormat = formatter;
    if ([obj isKindOfClass:[NSDate class]]) {
        return [dateFormat stringFromDate:obj];
    }
    return [dateFormat dateFromString:obj];
}


